package org.opens.mybatisplus.controller;

import org.opens.mybatisplus.pojo.dto.MyBatisPerson;
import org.opens.util.R;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/api/axios")
@CrossOrigin(origins = "*", maxAge = 3600, allowCredentials = "true")
public class AxiosController {

    @RequestMapping(value = "/simple/param")
    public R getSimpleUrl(
            @RequestParam(value = "id") Integer id
    ) {
        R ok = R.success("ok");
        ok.put("id", id);
        return ok;
    }

    @RequestMapping(value = "/obj/param")
    public R getObjUrl(
            MyBatisPerson myBatisPerson
    ) {
        R ok = R.success("ok");
        ok.put("person", myBatisPerson);
        return ok;
    }

    @RequestMapping(value = "/json/param")
    public R getJsonUrl(
            @RequestBody MyBatisPerson myBatisPerson
    ) {
        R ok = R.success("ok");
        ok.put("person", myBatisPerson);
        return ok;
    }

    @RequestMapping(value = "/path/param/{id}")
    public R getPathUrl(
            @PathVariable Integer id
    ) {
        R ok = R.success("ok");
        ok.put("id", id);
        return ok;
    }

}
